package com.qing.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qing.config.security.pojo.JwtUser;
import com.qing.pojo.vo.SignInVo;
import io.jsonwebtoken.Jwt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.qing.service.SignInService;
import com.qing.pojo.SignIn;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author qinghua
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/sign-in")
public class SignInController {
    @Autowired
    private SignInService signInService;

    @PostMapping("/insert")
    public Boolean save(@RequestBody SignIn signIn) {
        return signInService.saveOrUpdate(signIn);
    }

    @GetMapping("/signIn")
    public String signIn(@AuthenticationPrincipal JwtUser jwtUser) {
        return signInService.signIn(jwtUser.getId());
    }

    @GetMapping("/signOut")
    public String signOut(@AuthenticationPrincipal JwtUser jwtUser) {
        return signInService.signOut(jwtUser.getId());
    }

    @GetMapping("/updateSignInByEmployeeId/{id}")
    public Boolean updateSignInByEmployeeId(@PathVariable("id") Integer id) {
        return signInService.updateSignInByEmployeeId(id);
    }

    @GetMapping("/updateSignOutByEmployeeId/{id}")
    public String updateSignOutByEmployeeId(@PathVariable("id") Integer id) {
        return signInService.updateSignOutByEmployeeId(id);
    }

    @GetMapping("/deleteById/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return signInService.removeById(id);
    }

    @GetMapping("/queryAll")
    public List<SignIn> queryAll() {
        return signInService.list();
    }

    @GetMapping("/queryById/{id}")
    public SignIn findOne(@PathVariable Integer id) {
        return signInService.getById(id);
    }

    @GetMapping("/queryByEmployeeId")
    public Boolean queryByEmployeeId(@AuthenticationPrincipal JwtUser jwtUser) {
        return signInService.queryByEmployeeId(jwtUser.getId()) != null;
    }

    @GetMapping("/queryAllAndName")
    public List<SignInVo> queryAllAndName() {
        return signInService.queryAllAndName();
    }

}

